package org.ljx.taobao.controller;

import org.ljx.taobao.api.IShoppingService;
import org.ljx.taobao.api.entity.Shopping;
import org.ljx.taobao.service.ShoppingServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author: Ljx
 * @Date: 2021/12/31 11:55
 * @role: 清除某用户的所有订单
 */
@WebServlet("/clear")
public class ClearServlet extends HttpServlet {
    public static boolean x;
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;utf-8");
        Shopping shopping = new Shopping();
        IShoppingService iShoppingService = new ShoppingServiceImpl();
        HttpSession session = req.getSession();
        List<Shopping> list = new ArrayList<>();
        session.setAttribute("shop",list);
        x = iShoppingService.clear(shopping);
        if (x){
            resp.sendRedirect("shopping.jsp");
        }
    }
}

